<?php
/**
 * 旅馆管理
 *
 * @copyright Copyright © 2008 harry
 * @author harry 
 * @subpackage room
 * 
 */
FLEA::loadClass('controller_Abstruct');
class controller_FrontAdminHotel extends controller_Abstruct
{
	/**
	 * 城市
	 *
	 * @var unknown_type
	 */
	var $hotel;
	var $city;
	
	function __construct()
	{
		parent::__construct();
		$this->hotel =& FLEA::getSingleton('table_SysHotel');
		$this->city =& FLEA::getSingleton('table_SysCity');
		if($this->hotel->find(array('user_id'=>$_SESSION['CMS']['ID'])))
		{
			$this->smarty->assign(array('hotelstate'=>'true'));
		}
	}
	/**
	 * 旅馆
	 *
	 */
	function __FrontAdminHotelIndex()
	{
		//$hotel = $this->hotel->findAll();
		$this->smarty->assign(
			array('hotel'=>$hotel)
		);
		dump($_SESSION);
		$this->smarty->display('default/hotel/hotelindex.tpl');
	}
	/**
	 * 增加旅馆
	 *
	 */
	function __FrontAdminAddHotel()
	{
		$citylist = $this->city->findAll(array('delete'=>1));
		if($_POST)
		{
			$this->hotel->save($_POST);
			redirect(url('FrontAdminHotel','FrontAdminHotelIndex'));
		}
		$this->smarty->assign(array(
					'citylist' => $citylist,
					'user_id'  => $_SESSION['CMS']['ID'],
				));
		$this->smarty->display('default/hotel/addhotel.tpl');
	}
	/**
	 * 编辑旅馆
	 *
	 */
	function __FrontAdminEditHotel()
	{
		$citylist = $this->city->findAll(array('delete'=>1));
		if($_POST)
		{
			$this->hotel->save($_POST);
			redirect(url('FrontAdminHotel','FrontAdminHotelIndex','',2000));
			//redirect($this->_url('FrontAdminHotelIndex','',15));
		}
		$hotelcontent = $this->hotel->find(array('user_id'  => $_SESSION['CMS']['ID']));
		$this->smarty->assign(array(
			'hotelcontent' => $hotelcontent,
			'citylist' => $citylist,
		));
		//dump($hotelcontent);
		//dump($citylist);
		$this->smarty->display('default/hotel/addhotel.tpl');
	}
	/**
	 * 改变旅馆状态 （禁用，启用）
	 *
	 */
	function __FrontAdminDeleteHotel()
	{
		if($_GET['city_id']){
			if($_GET['state']==1)
			{
				$conditions = array(
					'city_id' => $_GET['city_id'],
					'delete'  => 0,
				);
			}
			else
			{
				$conditions = array(
					'city_id' => $_GET['city_id'],
					'delete'  => 1,
				);
			}
			$this->city->save($conditions);
			//$city = $this->city->removeByPkv($_GET['city_id']);
		}
		redirect(url('AdminCity','CityIndex'));
	}
}